package com.qfmy.webapp.service.impl.wallpaper;


import com.qfmy.model.entity.wallpaper.WallpaperCategory;
import com.qfmy.model.vo.wallpaper.WallpaperCategoryVo;
import com.qfmy.webapp.mapper.wallpaper.WallpaperCategoryMapper;
import com.qfmy.webapp.service.wallpaper.WallpaperCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @author 清风明月
 * @Package com.qfmy.web.app.service.impl.wallpaper
 * @date 2025/11/26
 * @description 壁纸分类
 */
@Service
@SuppressWarnings("all")
public class WallpaperCategoryServiceImpl implements WallpaperCategoryService {

    /**
     * 注入mapper
     */
    @Autowired
    private WallpaperCategoryMapper wallpaperCategory;

    /**
     * 注入redis
     * @param type
     * @return
     */
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @Override
    public List<WallpaperCategoryVo> getWallpaperCategoryNameByType(Integer type) {
        //缓存没有数据查询数据库
        List<WallpaperCategory> wallpaperCategoryList = wallpaperCategory.getWallpaperCategoryNameByType(type);
        //判是否有数据
        if(wallpaperCategoryList != null)
        {
            //转换vo
            List<WallpaperCategoryVo> wallpaperCategoryVos = wallpaperCategoryList.stream().map(wallpaperCategory -> new WallpaperCategoryVo(wallpaperCategory.getId(), wallpaperCategory.getName(), wallpaperCategory.getIconUrl())).toList();
            return wallpaperCategoryVos;
        }
        return Collections.emptyList();
    }
}
